package com.xgst.baselib

import android.content.Intent
import android.os.Bundle
import android.view.LayoutInflater
import androidx.appcompat.app.AppCompatActivity
import androidx.viewbinding.ViewBinding
import com.blankj.utilcode.util.AdaptScreenUtils
import com.gym.baselib.utils.ProgressUtils
import java.lang.reflect.ParameterizedType

open abstract class BaseActivity<VB : ViewBinding>:AppCompatActivity() {
    private var _binding: VB? = null
    protected val binding get() = _binding!!

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)

        val superClass = (javaClass.genericSuperclass as ParameterizedType).actualTypeArguments[0] as Class<VB>
        val method = superClass.getMethod("inflate", LayoutInflater::class.java)
        _binding = method.invoke(null, layoutInflater) as VB
        setContentView(binding.root)

        init()
    }

    override fun getResources() = AdaptScreenUtils.adaptWidth(super.getResources(), 1920)

    protected abstract fun init()

    fun startActivity(cls:Class<*>){
        startActivity(Intent(this,cls))
    }

    fun showProgress() = ProgressUtils.showProgress()
}